package me.zhulu.cglib;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 * User: herosea
 * Date: 14-4-17
 * Time: 下午4:12
 * To change this template use File | Settings | File Templates.
 */
public class AuthProxy implements MethodInterceptor {

    private String name;

    public AuthProxy(String name) {
        this.name = name;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        if (!"张三".equals(name)) {
            System.out.println("你没有权限！");
            return null;
        }
        return methodProxy.invokeSuper(o, objects);
    }
}
